package com.vrms.app.controller;

import com.vrms.app.aop.SystemControllerLog;
import com.vrms.app.entity.Bed;
import com.vrms.app.service.BedService;
import com.vrms.app.tools.CommonResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("bed")

@CrossOrigin
public class BedController {
    @Resource
    private BedService bedService;

    @GetMapping("/listPage")
    @SystemControllerLog(description = "分页查询床位信息")
    public CommonResult listPage(int page, int size, String bedInfo){
        Map<String,Object> map = new HashMap();
        map.put("count",bedService.count(bedInfo));
        map.put("data",bedService.listPage(page,size,bedInfo));
        return CommonResult.success(map);
    }

    @PostMapping("/save")
    @SystemControllerLog(description = "添加床位")
    public CommonResult save(@RequestBody Bed bed){
        return CommonResult.success(bedService.save(bed));
    }

    @PostMapping("/update")
    @SystemControllerLog(description = "更新床位信息")
    public CommonResult update(@RequestBody Bed bed){
        return CommonResult.success(bedService.update(bed));
    }

    @PostMapping("/remove")
    @SystemControllerLog(description = "根据ID删除床位信息")
    public CommonResult remove(int id){
        return CommonResult.success(bedService.remove(id));
    }

    @PostMapping("/list")
    @SystemControllerLog(description = "查询所有床位信息")
    public CommonResult list(){
        return CommonResult.success(bedService.list());
    }
}
